function writeDataToFile (fileName, data)
fid = fopen(fileName, 'w');
[~, tNum] = size (data);
[~, len ] = size (data{1}.X);

for k = 1:tNum
    for j = 1:len
        for i = 1:len
            if ((j == 1) && (i == 1))
                fprintf (fid, '%d', data{k}.Y(i,j));
            else
                fprintf (fid, ',%d', data{k}.Y(i,j));
            end
        end
    end
    for j = 1:len
        for i = 1:len
            fprintf (fid, ',%d', data{k}.X(i,j));
        end
    end
    fprintf (fid, '\n');
end

fclose(fid);